<template>
    <div class="all-container">
        <el-tabs v-model="activeTab">
            <el-tab-pane label="帐号总览" name="account">
                <account></account>
            </el-tab-pane>
            <el-tab-pane label="一键三连" name="source">
                <SpiderSource :statusBtns="statusBtns" :batch="0" buttonName="配置" @handleSetting="handleSetting" />
            </el-tab-pane>
            <el-tab-pane label="三连列表" name="status">
                <OverviewJobList />
            </el-tab-pane>
        </el-tabs>
        <el-dialog title="添加任务" :visible.sync="dialogFormVisible" destroy-on-close @close="handleDialogClose"
            width="470px">
            <JSCron ref="jsCron" v-if="dialogFormVisible" />
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false" size="mini">取 消</el-button>
                <el-button type="primary" @click="handleDialogSave('jsCron')" size="mini">确
                    定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<style lang="scss">
.all-container {
    .el-dialog__body {
        padding-bottom: 0px !important;
        padding-top: 10px !important;
    }
}
</style>

<script>
const { ipcRenderer: ipc } = require('electron')
import { TaskJobDao } from '@/dao/taskJobDao'
import { UsageScope } from '@/entities/Constant'
import { UniqueID, DeepCopy } from '@/utils/Utils'

import JSCron from "@/components/Common/JSCron"
import Account from "@/views/media/common/Account"
import SpiderSource from "@/views/media/spider/spiderSource"
import OverviewJobList from "@/views/media/overview/overviewJobList"

export default {
    name: "all",
    components: { JSCron, Account, SpiderSource, OverviewJobList },
    data() {
        return {
            source: {},
            activeTab: "account",
            dialogFormVisible: false,
            statusBtns: [
                { status: 0, name: "待采集", key: "status" },
                { status: 1, name: "已采集", key: "status" },
            ]
        }
    },
    methods: {
        handleSetting(args) {
            this.source = args
            this.dialogFormVisible = true
        },
        handleDialogClose() {
            this.source = {}
        },
        handleDialogSave(refName) {
            let jobCode = UniqueID(1)
            let source = DeepCopy(this.source)
            let jobCron = DeepCopy(this.$refs[refName].form)
            TaskJobDao.saveSourceJob(source, jobCron, jobCode, UsageScope.Spider).then(job => {
                this.dialogFormVisible = false
                if (job.id > 0) {
                    this.$message.success("添加成功,请耐心等待")
                    ipc.send("puppeteer", { data: job, raw: 0 })
                } else {
                    this.$message.error("添加失败,请重试")
                }
            })
        }
    },
}
</script>